//-----------------------------------------------------------------------------
// Copyright 2008 Andrés M. R. Martano
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>
//-----------------------------------------------------------------------------

#ifndef FOGO_H_
#define FOGO_H_

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_opengl.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <math.h>
#include <iostream>
using namespace std;

#define TAMANHO 1 //Multiplica o tamanho geral das coisas

//Uma posição qualquer
typedef struct posicao2{
		float x, y, z;
		float xr, zr;

		void mudar(float x2, float y2, float z2){ x = x2; y = y2; z = z2; }
		void adicionar(float x2, float y2, float z2){ x += x2; y += y2; z += z2; }
		void igualar(struct posicao2 pos2){x = pos2.x; y = pos2.y; z = pos2.z; xr = pos2.xr; zr = pos2.zr;};
		void mudar_r( float xr2, float zr2 ){ xr = xr2; zr = zr2; }
		void rodar( float x2, float z2 )
		{
			xr += x2;
			zr += z2;
			//if( xr < -90 ) xr = -90;
			//if( xr > 90 ) xr = 90;
			if( xr >= 360 ) xr = 0;
			if( xr <= -360) xr = 0;
			if( zr >= 360 ) zr = 0;
			if( zr <= -360) zr = 0;
		}
}posicao;

//A CÂMERA
typedef struct{
		posicao pos;
		//posicao pos2;
		float vel_mov;
		float vel_rot;

		void iniciar()
		{
			pos.mudar( 0*TAMANHO , 0*TAMANHO, 5*TAMANHO );
			pos.mudar_r( 0, 0 );

			//pos2.mudar( 0*TAMANHO , 0*TAMANHO, 0*TAMANHO );
			//pos2.mudar_r( 0, 0 );

			vel_mov = 2;
			vel_rot = 10;
		}
		void imprimir()
		{
			//cout << "\nCAMERA(" << pos.x << "," << pos.y << "," << pos.z <<  ")";
			//cout << "(" << pos.xr << "," << pos.zr <<  ")\n";
		}
		void rodar( float x, float z )
		{
			pos.rodar( x*vel_rot, z*vel_rot );
		}
		void mover( float x, float y, float z )
		{
			pos.adicionar( x*vel_mov*cos(0.01745*pos.zr)+y*vel_mov*sin(0.01745*pos.zr), y*vel_mov*cos(0.01745*pos.zr)-x*vel_mov*sin(0.01745*pos.zr), z*vel_mov );
		}
		void posicionar()
		{
			glRotatef(-pos.xr-90,1.0,0.0,0.0);
			glRotatef(pos.zr,0.0,0.0,1.0);
			glTranslatef(-pos.x,-pos.y,-pos.z);
		}
		//void posicionar2()
		//{

			//glBegin( GL_QUADS );
			//glNormal3f( 0.0f, 0.0f, 1.0f );
			////XX
			////OX
			//glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -0.5f, -10.5f, 0.0f );
			////XX
			////XO
			//glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 10.5f, -0.5f, 0.0f );
			////XO
			////XX
			//glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 10.5f, 0.5f, 2.0f );
			////OX
			////XX
			//glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -0.5f, 0.5f, 0.0f );
			//glEnd( );

			////glRotatef(-pos2.zr,1.0,1.0,1.0);

			////glPushMatrix();
			////glTranslatef(-pos2.x,-pos2.z,pos2.y);
			////glPopMatrix();

			////glRotatef(pos2.xr,1.0,0.0,0.0);
			////glRotatef(pos2.xr,1.0,0.0,0.0);
			////glRotatef(-pos2.zr*cos(0.01745*pos2.xr),0.0,0.0,1.0);
			////glRotatef(-pos2.zr*sin(0.01745*pos2.xr),0.0,-1.0,0.0);


		//}
} camera;

//Serve de base para as coisas que tem formato
class coisa
{
	protected:
		int desenho;
		int coluna;
	public:
		float tamanho;
		posicao pos;

		coisa( int coluna );
		virtual ~coisa();
		virtual void desenhar(void) = 0;
};

//Uma coisa com formato 2D quadrado
class plano : public coisa
{
	public:

		//pos2 - posição em que será criado
		//tama - tamanho dessa coisa
		//dese - número de sua textura
		plano( posicao pos2, float tama, int dese, int coluna );

		void desenhar(void);
};

//-----------------------------------------------------------------------------
//EXTERNS
//-----------------------------------------------------------------------------
extern camera cam;

//-----------------------------------------------------------------------------
//PROTÓTIPOS
//-----------------------------------------------------------------------------

//carrega uma textura para ser usada futuramente
//	nome - nome do arquivo da textura
//	pos - posição na lista de texturas ( de 0 a N_TEXTURAS )
int carregar_textura( const char nome[20], int pos );

//limpa o buffer
char desenhar_listas_inicio();

//desenha todas as coisas que estão na lista de desenho
char desenhar_lista( int coluna, float x, float y, float z );

//atualiza o buffer
char desenhar_listas_fim();

//carrega esta biblioteca
char acender_fogo( int colunas );

//descarrega essa biblioteca
char apagar_fogo();

#endif /*FOGO_H_*/
